<?php


namespace App\Http\observer;


use App\Jobs\ImageUpdatedJob;
use App\Jobs\QeditDeletImageJob;
use App\Models\Active;
use App\Models\Image;
use Illuminate\Support\Facades\Cache;

class ActiveObserver
{
    public function deleted(Active $active)
    {
        $imgModel=new Image();
        $img=$imgModel->where("url",$active->icon)->value("id");
        if ($img){
            $imgModel->find($img)->delete();
        }
        QeditDeletImageJob::dispatch($active->content);
    }

    public function updating(Active $active)
    {
        $old=Active::where("id",$active->id)->first();
        if($old["icon"]!=$active->icon){
            Cache::put("url",$old["icon"]);
        }
        Cache::put("qedit",$active->content);
        Cache::put("oqedit",$old["content"]);
    }



    public function updated(Active $active)
    {
        ImageUpdatedJob::dispatch();
    }
}
